package com.ds.console.service;

import com.ds.common.Page;
import com.ds.common.PageInfo;
import com.ds.common.util.BeanUtil;
import com.ds.console.bo.TFileBo;
import com.ds.console.entity.TFile;
import com.ds.console.mapper.TFileMapper;
import com.ds.console.vo.TFileVo;
import com.github.pagehelper.PageHelper;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import java.io.Serializable;


@Slf4j
@Service
@RequiredArgsConstructor
public class TFileService {

    private final TFileMapper tFileMapper;

    public boolean insert(TFileBo param) {
        TFile entity = BeanUtil.copyProperties(param, TFile.class);
        int count = tFileMapper.insert(entity);
        return count > 0;
    }

    public boolean update(TFileBo param) {
        TFile entity = BeanUtil.copyProperties(param, TFile.class);
        int count = tFileMapper.updateById(entity);
        return count > 0;
    }

    public boolean delete(Serializable id) {
        int count = tFileMapper.deleteById(id);
        return count > 0;
    }

    public TFileVo select(Serializable id) {
        TFile entity = tFileMapper.selectById(id);
        return BeanUtil.copyProperties(entity, TFileVo.class);
    }

    public PageInfo<TFileVo> selectPage(Page<TFileBo> param) {
        PageHelper.startPage(param.getPageNum(), param.getPageSize());
        return PageInfo.build(tFileMapper.selects(param.getParam()));
    }

}